package org.wd.extractor.cleartrip;

import java.util.List;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

public class ClearTripInfoExtractor {

	private WebDriver driver;
	
	public ClearTripInfoExtractor() {
		this.driver = new HtmlUnitDriver();
	}

	public void extractAllStationInfo() {
		driver.get("http://www.cleartrip.com/trains/stations/list");

		List<List<String>> rowsList = WebdriverUtil.getTableContents(driver, "id('ContentFrame')/div[1]/div/table");
		List<String> currentRow;
		for (int i = 0; i < rowsList.size(); i++) {
			currentRow = rowsList.get(i);
			for (int j = 0; j < currentRow.size(); j++)
				System.out.print(currentRow.get(j) + " ");
			System.out.println();
		}
	}

	public void extractStationTrainInfo(String stationCode) {
		driver.get("http://www.cleartrip.com/trains/stations/" + stationCode);

		List<List<String>> rowsList = WebdriverUtil.getTableContents(driver, "id('ContentFrame')/div[2]/div/table");
		List<String> currentRow;
		for (int i = 0; i < rowsList.size(); i++) {
			currentRow = rowsList.get(i);
			for (int j = 0; j < currentRow.size(); j++)
				System.out.print(currentRow.get(j) + " ");
			System.out.println();
		}
	}

	public void extractTrainInfo(String trainNumber) {
		driver.get("http://www.cleartrip.com/trains/" + trainNumber);

		List<List<String>> rowsList = WebdriverUtil.getTableContents(driver, "id('ContentFrame')/div[2]/div/table");
		List<String> currentRow;
		for (int i = 0; i < rowsList.size(); i++) {
			currentRow = rowsList.get(i);
			for (int j = 0; j < currentRow.size(); j++)
				System.out.print(currentRow.get(j) + " ");
			System.out.println();
		}
	}
	
	public void closeDriver() {
		driver.close();
	}
}
